/*==============================================================*/
/* DBMS name:      Microsoft SQL Server 2008                    */
/* Created on:     6/17/2012 2:28:39 PM                         */
/*==============================================================*/



if exists (select 1
          from sysobjects
          where id = object_id('CLR_TRIGGER_BUKU')
          and type = 'TR')
   drop trigger CLR_TRIGGER_BUKU
go

if exists (select 1
          from sysobjects
          where id = object_id('CLR_TRIGGER_CD')
          and type = 'TR')
   drop trigger CLR_TRIGGER_CD
go

if exists (select 1
          from sysobjects
          where id = object_id('CLR_TRIGGER_DETAIL_DATA_KATEGORI')
          and type = 'TR')
   drop trigger CLR_TRIGGER_DETAIL_DATA_KATEGORI
go

if exists (select 1
          from sysobjects
          where id = object_id('CLR_TRIGGER_DETAIL_DATA_PENGARANG')
          and type = 'TR')
   drop trigger CLR_TRIGGER_DETAIL_DATA_PENGARANG
go

if exists (select 1
          from sysobjects
          where id = object_id('CLR_TRIGGER_ITEMS')
          and type = 'TR')
   drop trigger CLR_TRIGGER_ITEMS
go

if exists (select 1
          from sysobjects
          where id = object_id('CLR_TRIGGER_REVIEW')
          and type = 'TR')
   drop trigger CLR_TRIGGER_REVIEW
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('BOOKING')
            and   name  = 'RELATIONSHIP_14_FK'
            and   indid > 0
            and   indid < 255)
   drop index BOOKING.RELATIONSHIP_14_FK
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('BOOKING')
            and   name  = 'RELATIONSHIP_13_FK'
            and   indid > 0
            and   indid < 255)
   drop index BOOKING.RELATIONSHIP_13_FK
go

if exists (select 1
            from  sysobjects
           where  id = object_id('BOOKING')
            and   type = 'U')
   drop table BOOKING
go

if exists (select 1
            from  sysobjects
           where  id = object_id('BUKU')
            and   type = 'U')
   drop table BUKU
go

if exists (select 1
            from  sysobjects
           where  id = object_id('CD')
            and   type = 'U')
   drop table CD
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('DENDA')
            and   name  = 'RELATIONSHIP_18_FK'
            and   indid > 0
            and   indid < 255)
   drop index DENDA.RELATIONSHIP_18_FK
go

if exists (select 1
            from  sysobjects
           where  id = object_id('DENDA')
            and   type = 'U')
   drop table DENDA
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('DETAIL_DATA_KATEGORI')
            and   name  = 'RELATIONSHIP_11_FK'
            and   indid > 0
            and   indid < 255)
   drop index DETAIL_DATA_KATEGORI.RELATIONSHIP_11_FK
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('DETAIL_DATA_KATEGORI')
            and   name  = 'RELATIONSHIP_22_FK'
            and   indid > 0
            and   indid < 255)
   drop index DETAIL_DATA_KATEGORI.RELATIONSHIP_22_FK
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('DETAIL_DATA_KATEGORI')
            and   name  = 'RELATIONSHIP_12_FK'
            and   indid > 0
            and   indid < 255)
   drop index DETAIL_DATA_KATEGORI.RELATIONSHIP_12_FK
go

if exists (select 1
            from  sysobjects
           where  id = object_id('DETAIL_DATA_KATEGORI')
            and   type = 'U')
   drop table DETAIL_DATA_KATEGORI
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('DETAIL_DATA_PENGARANG')
            and   name  = 'RELATIONSHIP_19_FK'
            and   indid > 0
            and   indid < 255)
   drop index DETAIL_DATA_PENGARANG.RELATIONSHIP_19_FK
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('DETAIL_DATA_PENGARANG')
            and   name  = 'RELATIONSHIP_23_FK'
            and   indid > 0
            and   indid < 255)
   drop index DETAIL_DATA_PENGARANG.RELATIONSHIP_23_FK
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('DETAIL_DATA_PENGARANG')
            and   name  = 'RELATIONSHIP_20_FK'
            and   indid > 0
            and   indid < 255)
   drop index DETAIL_DATA_PENGARANG.RELATIONSHIP_20_FK
go

if exists (select 1
            from  sysobjects
           where  id = object_id('DETAIL_DATA_PENGARANG')
            and   type = 'U')
   drop table DETAIL_DATA_PENGARANG
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('ITEMS')
            and   name  = 'RELATIONSHIP_5_FK'
            and   indid > 0
            and   indid < 255)
   drop index ITEMS.RELATIONSHIP_5_FK
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('ITEMS')
            and   name  = 'RELATIONSHIP_6_FK'
            and   indid > 0
            and   indid < 255)
   drop index ITEMS.RELATIONSHIP_6_FK
go

if exists (select 1
            from  sysobjects
           where  id = object_id('ITEMS')
            and   type = 'U')
   drop table ITEMS
go

if exists (select 1
            from  sysobjects
           where  id = object_id('KATEGORI')
            and   type = 'U')
   drop table KATEGORI
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('ORANG')
            and   name  = 'USERNAME_INDEX'
            and   indid > 0
            and   indid < 255)
   drop index ORANG.USERNAME_INDEX
go

if exists (select 1
            from  sysobjects
           where  id = object_id('ORANG')
            and   type = 'U')
   drop table ORANG
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('PEMINJAM')
            and   name  = 'RELATIONSHIP_17_FK'
            and   indid > 0
            and   indid < 255)
   drop index PEMINJAM.RELATIONSHIP_17_FK
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('PEMINJAM')
            and   name  = 'RELATIONSHIP_10_FK'
            and   indid > 0
            and   indid < 255)
   drop index PEMINJAM.RELATIONSHIP_10_FK
go

if exists (select 1
            from  sysobjects
           where  id = object_id('PEMINJAM')
            and   type = 'U')
   drop table PEMINJAM
go

if exists (select 1
            from  sysobjects
           where  id = object_id('PENGARANG')
            and   type = 'U')
   drop table PENGARANG
go

if exists (select 1
            from  sysobjects
           where  id = object_id('REQUEST_BUKU')
            and   type = 'U')
   drop table REQUEST_BUKU
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('REVIEW')
            and   name  = 'RELATIONSHIP_16_FK'
            and   indid > 0
            and   indid < 255)
   drop index REVIEW.RELATIONSHIP_16_FK
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('REVIEW')
            and   name  = 'RELATIONSHIP_21_FK'
            and   indid > 0
            and   indid < 255)
   drop index REVIEW.RELATIONSHIP_21_FK
go

if exists (select 1
            from  sysindexes
           where  id    = object_id('REVIEW')
            and   name  = 'RELATIONSHIP_15_FK'
            and   indid > 0
            and   indid < 255)
   drop index REVIEW.RELATIONSHIP_15_FK
go

if exists (select 1
            from  sysobjects
           where  id = object_id('REVIEW')
            and   type = 'U')
   drop table REVIEW
go

/*==============================================================*/
/* Table: BOOKING                                               */
/*==============================================================*/
create table BOOKING (
   ID_ORANG             varchar(25)          not null,
   ID_ITEMS             varchar(25)          not null,
   ID_BOOKING           varchar(25)          not null,
   TANGGAL_BOOKING      datetime             null,
   STATUS_BOOKING       int                  null,
   constraint PK_BOOKING primary key nonclustered (ID_BOOKING)
)
go

/*==============================================================*/
/* Index: RELATIONSHIP_13_FK                                    */
/*==============================================================*/
create index RELATIONSHIP_13_FK on BOOKING (
ID_ORANG ASC
)
go

/*==============================================================*/
/* Index: RELATIONSHIP_14_FK                                    */
/*==============================================================*/
create index RELATIONSHIP_14_FK on BOOKING (
ID_ITEMS ASC
)
go

/*==============================================================*/
/* Table: BUKU                                                  */
/*==============================================================*/
create table BUKU (
   ID_DATA              varchar(25)          not null,
   JUMLAH_HALAMAN_DATA  int                  null,
   ISBN_DATA            varchar(40)          null,
   TAHUN_DATA           int                  null,
   JUDUL_DATA           varchar(30)          null,
   GAMBAR_DATA          varbinary(Max)       null,
   constraint PK_BUKU primary key (ID_DATA)
)
go

/*==============================================================*/
/* Table: CD                                                    */
/*==============================================================*/
create table CD (
   ID_DATA              varchar(25)          not null,
   UKURAN_DATA          int                  null,
   TAHUN_DATA           int                  null,
   JUDUL_DATA           varchar(30)          null,
   GAMBAR_DATA          varbinary(Max)       null,
   constraint PK_CD primary key (ID_DATA)
)
go

/*==============================================================*/
/* Table: DENDA                                                 */
/*==============================================================*/
create table DENDA (
   ID_DENDA             varchar(25)          not null,
   ID_PEMINJAM          varchar(30)          null,
   JUMLAH_DENDA         int                  null,
   TANGGAL_DENDA        datetime             null,
   EKSIS_DENDA          int                  null,
   constraint PK_DENDA primary key nonclustered (ID_DENDA)
)
go

/*==============================================================*/
/* Index: RELATIONSHIP_18_FK                                    */
/*==============================================================*/
create index RELATIONSHIP_18_FK on DENDA (
ID_PEMINJAM ASC
)
go

/*==============================================================*/
/* Table: DETAIL_DATA_KATEGORI                                  */
/*==============================================================*/
create table DETAIL_DATA_KATEGORI (
   ID_KATEGORI          varchar(25)          not null,
   ID_DATA              varchar(25)          null,
   DAT_ID_DATA          varchar(25)          null,
   ID_DETAIL_KATEGORI   numeric          identity	not null,
   constraint PK_DETAIL_DATA_KATEGORI primary key nonclustered (ID_DETAIL_KATEGORI)
)
go

/*==============================================================*/
/* Index: RELATIONSHIP_12_FK                                    */
/*==============================================================*/
create index RELATIONSHIP_12_FK on DETAIL_DATA_KATEGORI (
ID_KATEGORI ASC
)
go

/*==============================================================*/
/* Index: RELATIONSHIP_22_FK                                    */
/*==============================================================*/
create index RELATIONSHIP_22_FK on DETAIL_DATA_KATEGORI (
ID_DATA ASC
)
go

/*==============================================================*/
/* Index: RELATIONSHIP_11_FK                                    */
/*==============================================================*/
create index RELATIONSHIP_11_FK on DETAIL_DATA_KATEGORI (
DAT_ID_DATA ASC
)
go

/*==============================================================*/
/* Table: DETAIL_DATA_PENGARANG                                 */
/*==============================================================*/
create table DETAIL_DATA_PENGARANG (
   ID_PENGARANG         varchar(25)          not null,
   ID_DATA              varchar(25)          null,
   DAT_ID_DATA          varchar(25)          null,
   ID_DETAIL_PENGARANG  numeric          identity	not null,
   constraint PK_DETAIL_DATA_PENGARANG primary key nonclustered (ID_DETAIL_PENGARANG)
)
go

/*==============================================================*/
/* Index: RELATIONSHIP_20_FK                                    */
/*==============================================================*/
create index RELATIONSHIP_20_FK on DETAIL_DATA_PENGARANG (
ID_PENGARANG ASC
)
go

/*==============================================================*/
/* Index: RELATIONSHIP_23_FK                                    */
/*==============================================================*/
create index RELATIONSHIP_23_FK on DETAIL_DATA_PENGARANG (
ID_DATA ASC
)
go

/*==============================================================*/
/* Index: RELATIONSHIP_19_FK                                    */
/*==============================================================*/
create index RELATIONSHIP_19_FK on DETAIL_DATA_PENGARANG (
DAT_ID_DATA ASC
)
go

/*==============================================================*/
/* Table: ITEMS                                                 */
/*==============================================================*/
create table ITEMS (
   ID_ITEMS             varchar(25)          not null,
   ID_DATA              varchar(25)          null,
   DAT_ID_DATA          varchar(25)          null,
   TANGGAL_PENYEDIAAN   datetime             null,
   JUMLAH_ITEM          int                  null,
   constraint PK_ITEMS primary key nonclustered (ID_ITEMS)
)
go

/*==============================================================*/
/* Index: RELATIONSHIP_6_FK                                     */
/*==============================================================*/
create index RELATIONSHIP_6_FK on ITEMS (
ID_DATA ASC
)
go

/*==============================================================*/
/* Index: RELATIONSHIP_5_FK                                     */
/*==============================================================*/
create index RELATIONSHIP_5_FK on ITEMS (
DAT_ID_DATA ASC
)
go

/*==============================================================*/
/* Table: KATEGORI                                              */
/*==============================================================*/
create table KATEGORI (
   ID_KATEGORI          varchar(25)          not null,
   NAMA_KATEGORI        varchar(30)          null,
   constraint PK_KATEGORI primary key nonclustered (ID_KATEGORI)
)
go

/*==============================================================*/
/* Table: ORANG                                                 */
/*==============================================================*/
create table ORANG (
   ID_ORANG             varchar(25)          not null,
   USERNAME_ORANG       varchar(25)          null,
   PASS_ORANG           varchar(25)          null,
   HAK_AKSES_ORANG      varchar(25)          null,
   EKSIS_ORANG          int                  null,
   constraint PK_ORANG primary key nonclustered (ID_ORANG)
)
go

/*==============================================================*/
/* Index: USERNAME_INDEX                                        */
/*==============================================================*/
create unique index USERNAME_INDEX on ORANG (
USERNAME_ORANG ASC
)
go

/*==============================================================*/
/* Table: PEMINJAM                                              */
/*==============================================================*/
create table PEMINJAM (
   ID_ORANG             varchar(25)          not null,
   ID_ITEMS             varchar(25)          not null,
   ID_PEMINJAM          varchar(30)          not null,
   TANGGAL_PINJAM       datetime             null,
   STATUS_PINJAM        int                  null,
   TANGGAL_KEMBALI      datetime             null,
   TANGGAL_HARUSNYA_KEMBALI datetime		 null,
   constraint PK_PEMINJAM primary key nonclustered (ID_PEMINJAM)
)
go

/*==============================================================*/
/* Index: RELATIONSHIP_10_FK                                    */
/*==============================================================*/
create index RELATIONSHIP_10_FK on PEMINJAM (
ID_ORANG ASC
)
go

/*==============================================================*/
/* Index: RELATIONSHIP_17_FK                                    */
/*==============================================================*/
create index RELATIONSHIP_17_FK on PEMINJAM (
ID_ITEMS ASC
)
go

/*==============================================================*/
/* Table: PENGARANG                                             */
/*==============================================================*/
create table PENGARANG (
   ID_PENGARANG         varchar(25)          not null,
   NAMA_PENGARANG       varchar(30)          null,
   EKSIS_PENGARANG      int                  null,
   constraint PK_PENGARANG primary key nonclustered (ID_PENGARANG)
)
go

/*==============================================================*/
/* Table: REQUEST_BUKU                                          */
/*==============================================================*/
create table REQUEST_BUKU (
   ID_REQUEST_BUKU      varchar(25)          not null,
   JUDUL_REQUEST_BUKU   varchar(35)          null,
   PENGARANG_REQUEST_BUKU varchar(50)          null,
   PENERBIT_REQUEST_BUKU varchar(35)          null,
   constraint PK_REQUEST_BUKU primary key nonclustered (ID_REQUEST_BUKU)
)
go

/*==============================================================*/
/* Table: REVIEW                                                */
/*==============================================================*/
create table REVIEW (
   ID_ORANG             varchar(25)          not null,
   ID_DATA              varchar(25)          null,
   DAT_ID_DATA          varchar(25)          null,
   ID_REVIEW            varchar(25)          not null,
   WAKTU_REVIEW         datetime             null,
   EKSIS_REVIEW         int                  null,
   ISI_REVIEW           nvarchar(Max)        null,
   constraint PK_REVIEW primary key nonclustered (ID_REVIEW)
)
go

/*==============================================================*/
/* Index: RELATIONSHIP_15_FK                                    */
/*==============================================================*/
create index RELATIONSHIP_15_FK on REVIEW (
ID_ORANG ASC
)
go

/*==============================================================*/
/* Index: RELATIONSHIP_21_FK                                    */
/*==============================================================*/
create index RELATIONSHIP_21_FK on REVIEW (
ID_DATA ASC
)
go

/*==============================================================*/
/* Index: RELATIONSHIP_16_FK                                    */
/*==============================================================*/
create index RELATIONSHIP_16_FK on REVIEW (
DAT_ID_DATA ASC
)
go

